<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <button type="button" onclick="testGet1();">测试GET</button>
    <button type="button" onclick="testGet2();">测试GET</button>
    <button type="button" onclick="testGet3();">测试GET</button>
    <button type="button" onclick="testGet4();">测试GET</button>
    <button type="button" onclick="testGet5();">测试GET</button>
    <br>
	<button type="button" onclick="testPost1();">测试POST</button>
    <button type="button" onclick="testPost2();">测试POST</button>
    <button type="button" onclick="testPost3();">测试POST</button>
    <button type="button" onclick="testPost4();">测试POST</button>
    <button type="button" onclick="testPost5();">测试POST</button>
	<div id="content">
			
	</div>
</body>
<script>
    function testGet1(){
        var ajax1 = new XMLHttpRequest();
        ajax1.open('GET','http://poetry.apiopen.top/poetry?count=2&page=1')
        ajax1.send();
        ajax1.onreadystatechange = function(){
            if(ajax1.readyState == 4 && ajax1.status == 200){
                var obj = JSON.parse(ajax1.responseText);
                
						document.getElementById('content').innerText = obj.result[0].content
						console.log(obj.result[0]);
					
            }
        }
        
    }
    function testGet2(){
        var ajax2 = new XMLHttpRequest();
        ajax2.open('GET','http://poetry.apiopen.top/getTime');
        ajax2.send();
        ajax2.onreadystatechange = function(){
            if(ajax2.readyState == 4 && ajax2.status == 200){
                var obj2 = JSON.parse(ajax2.responseText);
                document.getElementById('content').innerText = obj2.result.time+obj2.result.date;
                console.log(obj2.result.time)
            }
        }
    }
    function testGet3(){
        var ajax3 = new XMLHttpRequest();
        ajax3.open('GET','http://poetry.apiopen.top/sentences');
        ajax3.send();
        ajax3.onreadystatechange = function(){
            if(ajax3.readyState == 4 && ajax3.status == 200){
                var obj3 = JSON.parse(ajax3.responseText);
                document.getElementById('content').innerText = obj3.result.name;
            }
        }
    }
    function testGet4(){
        var ajax4 = new XMLHttpRequest();
        ajax4.open('GET','http://poetry.apiopen.top/poetryAuthor?count=2&page=1&name=李白');
        ajax4.send();
        ajax4.onreadystatechange = function(){
            if(ajax4.readyState == 4 && ajax4.status == 200){
                var obj4 = JSON.parse(ajax4.responseText);
                document.getElementById('content').innerText = obj4.result.simpleIntro;
            }
        }
    }
    function testGet5(){
        var ajax5 = new XMLHttpRequest();
        ajax5.open('GET','http://poetry.apiopen.top/poetryFull?count=2&page=1')
        ajax5.send();
        ajax5.onreadystatechange= function(){
            if(ajax5.readyState == 4 && ajax5.status == 200){
                var obj5 = JSON.parse(ajax5.responseText);
                document.getElementById('content').innerText = obj5.result[0].content;
                console.log(obj5.result[0].content)
            }
        }
    }
    function testPost1(){
        var ajax1 = new XMLHttpRequest();
        ajax1.open('POST','https://api.apiopen.top/updateUserInfo');
       // ajax1.setRequestHeader();
        ajax1.send('apikey="d0058f79caae5300dcba65f128e52855"&name="peakchao"&passwd="123456"');
        ajax1.onreadystatechange= function(){
            if(ajax1.readyState == 4 && ajax1.status ==200){
                var obj1 = JSON.parse(ajax1.responseText);
                document.getElementById('content').innerText = obj1.result;
                console.log(obj1.result)
            }
        }
    }
    function testPost2(){
        var ajax2 = new XMLHttpRequest();
        ajax2.open('POST','https://api.apiopen.top/getJoke');
        //ajax2.setRequestHeader();
        ajax2.send();
        ajax2.onreadystatechange = function(){
            if(ajax2.readyState==4 && ajax2.status==200){
                var obj2 = JSON.parse(ajax2.responseText);
                document.getElementById('content').innerText = obj2.result[0].text;
                console.log(obj2.result[0].text)
            }
        }
    }
    function testPost3(){
        var ajax3 = new XMLHttpRequest();
        ajax3.open('POST','https://api.apiopen.top/loginUser');
        //ajax3.setRequestHeader();
        ajax3.send('apikey="d0058f79caae5300dcba65f128e52855"&name="peakchao"&passwd="123456"');
        ajax3.onreadystatechange = function(){
            if(ajax3.readyState == 4 && ajax3.status==200){
                var obj3 = JSON.parse(ajax3.responseText);
                document.getElementById('content').innerText = obj3.result;
                console.log(obj3.result)
            }   
        }
    }
    function testPost4(){
        var ajax4 =new XMLHttpRequest();
        ajax4.open('POST','https://api.apiopen.top/getImages');
        //ajax4.setRequestHeader();
        ajax4.send('page=1&count=9');
        ajax4.onreadystatechange = function(){
            if(ajax4.readyState==4 && ajax4.status==200){
                var obj4 = JSON.parse(ajax4.responseText);
                document.getElementById('content').innerText = obj4.result[0].img;
                console.log(obj4.result[0].img)
            }
        }
    }
    function testPost5(){
        var ajax5 = new XMLHttpRequest();
        ajax5.open('POST','https://api.apiopen.top/getWangYiNews')
       // ajax5.setRequestHeader();
        ajax5.send('page=2&count=8');
        ajax5.onreadystatechange = function(){
            if(ajax5.readyState==4 && ajax5.status==200){
                var obj5 = JSON.parse(ajax5.responseText);
                document.getElementById('content').innerText = obj5.result[0].title;
                console.log(obj5.result[0].title)
            }
        }
    }
</script>
</html>